const jwt = require('jsonwebtoken');

const getToken = (data) => {
    return {
        token: jwt.sign({
            data
        }, "mi", { expiresIn: "7 days" })
    }
}

const verifyToken = (token) => {
    try {
        let data = jwt.verify(token, "mi")
        return {
            code: 200,
            msg: "解析成功",
            data
        }
    } catch (error) {
        return {
            code:400,
            msg: "token失效"
        }
    }
}

module.exports = {
    getToken,
    verifyToken
}